/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hendro.latihan.util;

import com.hendro.latihan.dao.StockDao;
import com.hendro.latihan.dao.impl.StockDaoImpl;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 *
 * @author Hendro
 */
public class StockDatabase {

    private static Connection connection;
    private static StockDao stockDao;

    public static Connection getConnection() throws SQLException {
        if (connection == null) {
            MysqlDataSource dataSource = new MysqlDataSource();
            dataSource.setUrl("jdbc:mysql://localhost:3306/latihan");
            dataSource.setUser("root");
            dataSource.setPassword("");

            connection = dataSource.getConnection();
        }
        return connection;
    }

    public static StockDao getStockDao() throws SQLException {
        if(stockDao == null){
            stockDao = new StockDaoImpl(getConnection());
        }
        return stockDao;
    }

}
